package com.kqb.controller;

import com.kqb.common.controller.base.BaseController;
import com.kqb.common.domain.AjaxResult;
import com.kqb.common.domain.ErrorResult;
import com.kqb.common.group.ApiGroups;
import com.kqb.pojo.Department;
import com.kqb.pojo.dto.DepartmentDto;
import com.kqb.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 杉果树皮
 * @date 2025/2/17 20:14
 * @description:
 */
@RestController
@RequestMapping("/api")
@Api(tags = "部门")
public class DepartmentController extends BaseController {
    @Autowired
    private IDepartmentService iDepartmentService;

    @GetMapping("/department")
    @ApiOperation("查看部门")
    public AjaxResult selectByPage(DepartmentDto departmentDTO) {
        return iDepartmentService.selectByPage(departmentDTO);
    }

    @GetMapping("/department/all")
    @ApiOperation("查看部门")
    public AjaxResult selectAll() {
        return iDepartmentService.selectAll();
    }

    @PostMapping("/department")
    @ApiOperation("添加部门")
    public AjaxResult save(@RequestBody DepartmentDto departmentDTO) {
        return iDepartmentService.save(departmentDTO);
    }

    @DeleteMapping("/department/{id}")
    @ApiOperation("删除部门")
    public AjaxResult deleteById(@PathVariable("id") Integer id) {
        return iDepartmentService.deleteById(id);
    }

    @PutMapping("/department")
    @ApiOperation("修改部门")
    public AjaxResult update(@Validated(ApiGroups.Update.class) @RequestBody Department department, BindingResult bindingResult) {
        ErrorResult.validate(bindingResult);
        return iDepartmentService.update(department);
    }


}
